package handle

import (
	"fileServer/cfile"
	"fileServer/global"
	"github.com/gin-gonic/gin"
	"os"
)

func GetDirPath(c *gin.Context) (dirPath string, err error) {
	path, err := ParsePath(c)
	if err != nil {
		return
	}
	filePath, err := cfile.SplitUrl(path.Path)
	if err != nil {
		global.GetResult(c).Error(400401, "路径错误", err.Error())
		return
	}
	dirPath = filePath + "/" + path.Dir
	return

}

func MakeDir(c *gin.Context) {
	dirName, _ := GetDirPath(c)
	if err := os.Mkdir(dirName, 0755); err != nil {
		global.GetResult(c).Error(400501, "创建目录失败", err.Error())
		return
	}
	global.GetResult(c).Success("创建文件成功")
}
